represents point or position, velocity and scale. Note! Angular velocity can not be represented by this type, it should be represented by Transform. It is a class inheriting numpy.ndarray, so it is also ndarray.
from py3d import Vector3
Vector3()
Welcome to py3d world, please visit https://tumiz.github.io/scenario/ for more information
Vector3([0., 0., 0.])
Vector3(x=1.2)
Vector3([1.2, 0. , 0. ])
Vector3(x=1, y=3, z=-2.4)
Vector3([ 1. , 3. , -2.4])
Vector3(x=1, y=3, z=-2.4, n=(2,))
Vector3([[ 1. , 3. , -2.4],
[ 1. , 3. , -2.4]])
Get unit vector
Vector3().U
Vector3([0., 0., 0.])
Get length
Vector3([1,2,3]).L
array([3.74165739])
Vector3([
[1,2,3],
[4,5,6]]).L
array([[3.74165739],
[8.77496439]])
Get a random vector
Vector3.Rand()
Vector3([0.44554818, 0.14620779, 0.82518622])
Get a random vector list
Vector3.Rand(3)
Vector3([[0.27114678, 0.80159729, 0.84279109],
[0.21441277, 0.19330337, 0.82606943],
[0.83885225, 0.81112912, 0.68952938]])
Cross product
Vector3(x=3).cross(Vector3(y=2))
Vector3([0., 0., 6.])
Display points
import plotly.express as px
p = Vector3.Rand(10).cumsum(axis=0)
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()
Use Vector3 as 2d vector
p=(Vector3.Rand(100)-0.5).U
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()